package com.chemical.search.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.chemical.search.dao.BaseAttributeDAO;
import com.chemical.search.model.BaseAttribute;
import com.chemical.search.service.IBaseAttributeService;
import com.chemical.search.util.page.Page;
import com.chemical.search.util.query.PropertyFilter;
import com.chemical.search.util.query.QueryUtil;

/**
 *@className:BaseAttributeServiceImpl.java
 *@classDescription:
 *@author:MChen
 *@createTime:2012-5-8
 */
@Service
@SuppressWarnings("unchecked")
public class BaseAttributeServiceImpl extends BaseService<BaseAttribute> implements IBaseAttributeService{
	
	@Resource(name = "baseAttributeDAO")
	private BaseAttributeDAO baseAttributeDAO;

	/**
	 * 根据CAS号获取相关信息 
	 */
	public BaseAttribute attributeInfoByCAS(String CAS) {
		String hql = "from BaseAttribute where cas_rn = '"+ CAS +"'";
		return this.baseAttributeDAO.find(hql);
	}
	
	/**
	 * 以Page形式返回结构信息
	 */
	public Page<BaseAttribute> searchAttribute(Page<BaseAttribute> page,List<PropertyFilter> pfList) {
		// 初始化hql
		StringBuffer hql = new StringBuffer("from BaseAttribute");
		// 设置查询条件
		String condition = QueryUtil.toSqlString(pfList, true);
		hql.append(condition);
		// 查找所有匹配的结构式总条数
		int totalCount = this.baseAttributeDAO.findCountBySql(hql.toString());
		page.setTotalCount(totalCount);
		// 是否存在排序
		if (page.isOrderBySetted()) {
			hql.append(page.getOrder());
		}
		System.out.println(hql+"======chem");
		List<BaseAttribute> list = this.baseAttributeDAO.findList(hql.toString(), page
				.getPageNo(), page.getPageSize());
		// 查出结果集
		page.setResult(list);
		return page;
	}
}
